package com.jingdianjichi.auth.application.controller;

import com.jindianjichi.common.entity.Result;
import com.jingdianjichi.auth.application.convert.AuthRoleDTOConverter;
import com.jingdianjichi.auth.application.convert.AuthUserDTOConverter;
import com.jingdianjichi.auth.application.dto.AuthRoleDTO;
import com.jingdianjichi.auth.application.dto.AuthUserDTO;
import com.jingdianjichi.auth.domain.entity.AuthRoleBO;
import com.jingdianjichi.auth.domain.entity.AuthUserBO;
import com.jingdianjichi.auth.domain.service.AuthRoleDomainService;
import com.jingdianjichi.auth.domain.service.AuthUserDomainService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;

@RestController
@RequestMapping("/role/")
@Slf4j
public class RoleController {

    @Resource
    private AuthRoleDomainService authRoleDomainService;


    @PostMapping("add")
    public Result<Boolean> registry(@RequestBody AuthRoleDTO authRoleDTO) {
        try {
            AuthRoleBO authRoleBO = AuthRoleDTOConverter.INSTANCE.convertDTOToBO(authRoleDTO);
            Boolean add = authRoleDomainService.add(authRoleBO);
            return Result.ok(add);
        } catch (Exception e) {
            log.error("注册失败:{}", e.getMessage());
            return Result.fail(false);
        }
    }

    @PostMapping("update")
    public Result<Boolean> update(@RequestBody AuthRoleDTO authRoleDTO) {
        try {
            AuthRoleBO authRoleBO = AuthRoleDTOConverter.INSTANCE.convertDTOToBO(authRoleDTO);
            Boolean update = authRoleDomainService.update(authRoleBO);
            return Result.ok(update);
        } catch (Exception e) {
            log.error("注册失败:{}", e.getMessage());
            return Result.fail(false);
        }
    }

    @PostMapping("delete")
    public Result<Boolean> delete(@RequestBody AuthRoleDTO authRoleDTO) {
        try {
            AuthRoleBO authRoleBO = AuthRoleDTOConverter.INSTANCE.convertDTOToBO(authRoleDTO);
            Boolean update = authRoleDomainService.delete(authRoleBO);
            return Result.ok(update);
        } catch (Exception e) {
            log.error("注册失败:{}", e.getMessage());
            return Result.fail(false);
        }
    }




}
